Repository navigation
Add functionality for Clement on the boundary - #21
Conversation
a59a2f9 to
18d06e1
Compare
|
|
||
| @PETSc.Log.EventDecorator() | ||
| def clement_interpolant(source, target=None): | ||
| def clement_interpolant(source, target=None, boundary=False): |
There was a problem hiding this comment.
Does this really need to be an option argument? Why not just have a clement_interpolant() and a boundary_clement_interpolant()? There's a bit of overlap, but not that much, and I can't really see a situation where you wanted the calling code to easily switch between the two: for the boundary version you end up with a function that you know only has values on the specified boundary, so presumably you're going to do something else with it than in the case of the non-boundary clement_interpolant
There was a problem hiding this comment.
Good point. Addressed in latest merge/commits.
| return facet_area | ||
|
|
||
|
|
||
| # TODO: Upstream as a cached_property of MeshGeometry in Firedrake (#17) |
There was a problem hiding this comment.
I suspect this doesn't quite do the right thing for "corner elements", cells with more than one exterior facet - e.g. the 2 corner triangles in a RectangleMesh: a vertex adjacent to such a corner triangle will receive the corner element value weighted by the edge length of both exterior edges of that corner element.
Out of interest, how are you planning to use this? The issue of corner elements (much more common in 3D) also raises the question of whether you actually want the multiple facets to have multiple values - in which case storing it as P0 field, i.e. in the subset of cells near the boundary, rather than in the facets, doesn't seem the right thing.
Could you do this using "submesh"? i.e. generate a submesh for the provided surface id, then if you do have a P0 volume field as source (i.e. single valued in corner elements) you can project/interpolate to a P0 (surface) field on the submesh, and then you should be able to use the non-boundary clement interpolation you already have, which gives you a P1 (surface) field on the submesh - which you could interpolate back to a P1 volume field if you wanted to...
There was a problem hiding this comment.
Could you do this using "submesh"? i.e. generate a submesh for the provided surface id, then if you do have a P0 volume field as source (i.e. single valued in corner elements) you can project/interpolate to a P0 (surface) field on the submesh, and then you should be able to use the non-boundary clement interpolation you already have, which gives you a P1 (surface) field on the submesh - which you could interpolate back to a P1 volume field if you wanted to...
Good suggestion. I've implemented it that way in recent commits.
I suspect this doesn't quite do the right thing for "corner elements", cells with more than one exterior facet - e.g. the 2 corner triangles in a RectangleMesh: a vertex adjacent to such a corner triangle will receive the corner element value weighted by the edge length of both exterior edges of that corner element.
The revised implementation should address this I think, although the tolerances are quite large in the tests.
Out of interest, how are you planning to use this? The issue of corner elements (much more common in 3D) also raises the question of whether you actually want the multiple facets to have multiple values - in which case storing it as P0 field, i.e. in the subset of cells near the boundary, rather than in the facets, doesn't seem the right thing.
The only current use cases is for the Hessian recovery on the boundary (currently in Animate) that is used in some formulations of anisotropic goal-oriented mesh adaptation. I think the approximate method here should be sufficient for that.
18d06e1 to
c9d97a9
Compare
stephankramer
left a comment
There was a problem hiding this comment.
Very nice, and some thorough testing!
| target, is_cofunction = _process_target(Vs, target) | ||
| rank = len(Vs.value_shape) | ||
| if rank not in (0, 1, 2): | ||
| raise ValueError(f"Rank-{rank + 1} tensors are not supported.") |
There was a problem hiding this comment.
Huh, I'd always thought a rank-1 tensor was a vector but it seems I'm wrong (https://en.wikipedia.org/wiki/Tensor_(intrinsic_definition)).
Fixed in 5f564cd. Note that there are a couple of places in Animate where this needs updating.
There was a problem hiding this comment.
I misremembered - actually it's fine in Animate now.
|
|
||
| # Interpolate back onto the P1 target on the volume mesh. Degrees of freedom not | ||
| # defined on the submesh are left unchanged, so zero the target first; submesh | ||
| # vertices which are not volume-mesh boundary vertices can still leak values |
There was a problem hiding this comment.
It might be obvious, but I can't immediately picture a situation where the submesh would have vertices that are not boundary vertices of the volume mesh - would you mind expanding/giving an example?
There was a problem hiding this comment.
Ah I think the code is correct but the explanation was wrong - see d185434.
Functionality here is now duplicated in `adapt_common` following merging mesh-adaptation/adapt_common#12 and mesh-adaptation/adapt_common#21, so can be removed from Animate.
Closes #15
Merges into #12
Extends the support for Clement on the boundary, as well as domain interior. Once merged, we can remove the duplicated Clement functionality from Animate.